package com.turbo.cloud.ums.web.webservice;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.base.PageQuery;
import com.turbo.cloud.core.validated.InsertValidated;
import com.turbo.cloud.core.validated.UpdateValidated;
import com.turbo.cloud.ums.web.logic.RoleLogic;
import com.turbo.cloud.ums.web.model.role.*;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户角色表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2022-10-11
 */
@RequiredArgsConstructor
@RestController
public class UmsRoleController {

    final RoleLogic roleLogic;

    /**
     * 查询角色分页列表
     *
     * @return
     */
    @PostMapping(name = "查询角色分页列表", value = "/webservice/role/queryRolePage")
    public Result<Page<UmsRoleVo>> queryRolePage(@RequestBody PageQuery<UmsRoleQo> pageQuery) {
        Page<UmsRoleVo> result = roleLogic.queryRolePage(pageQuery);
        return R.result(result);
    }

    /**
     * 新增角色
     *
     * @param umsRoleDo 实体
     * @return
     */
    @PostMapping(name = "新增角色", value = "/webservice/role/createRole")
    public Result<Boolean> createRole(@RequestBody @Validated(InsertValidated.class) UmsRoleDo umsRoleDo) {
        boolean result = roleLogic.createRole(umsRoleDo);
        return R.result(result);
    }

    /**
     * 修改角色
     *
     * @param umsRoleDo 实体
     * @return
     */
    @PostMapping(name = "修改角色", value = "/webservice/role/modifyRole")
    public Result<Boolean> modifyRole(@RequestBody @Validated(UpdateValidated.class) UmsRoleDo umsRoleDo) {
        boolean result = roleLogic.modifyRole(umsRoleDo);
        return R.result(result);
    }

    /**
     * 开启、关闭角色有效状态
     *
     * @param id 角色ID
     * @return
     */
    @GetMapping(name = "开启、关闭角色有效状态", value = "/webservice/role/enabledRoleStateById")
    public Result<Boolean> enabledRoleStateById(@RequestParam @NotBlank(message = "角色ID不能为空") String id) {
        boolean result = roleLogic.enabledRoleStateById(id);
        return R.result(result);
    }

    /**
     * 删除角色
     *
     * @param id 角色ID
     * @return
     */
    @GetMapping(name = "删除角色", value = "/webservice/role/removeRoleById")
    public Result<Boolean> removeRoleById(@RequestParam @NotBlank(message = "角色ID不能为空") String id) {
        boolean result = roleLogic.removeRoleById(id);
        return R.result(result);
    }

    /**
     * 绑定角色和权限关系
     *
     * @param umsRolePermissionRelationDo 实体
     * @return
     */
    @PostMapping(name = "绑定角色和权限关系", value = "/webservice/role/bindRolePermissionRelation")
    public Result<Boolean> bindRolePermissionRelation(@RequestBody @Validated(InsertValidated.class) UmsRolePermissionRelationDo umsRolePermissionRelationDo) {
        boolean result = roleLogic.bindRolePermissionRelation(umsRolePermissionRelationDo);
        return R.result(result);
    }

    /**
     * 解绑角色和权限关系
     *
     * @param umsRolePermissionRelationDo 实体
     * @return
     */
    @PostMapping(name = "解绑角色和权限关系", value = "/webservice/role/unBindRolePermissionRelation")
    public Result<Boolean> unBindRolePermissionRelation(@RequestBody @Validated(InsertValidated.class) UmsRolePermissionRelationDo umsRolePermissionRelationDo) {
        boolean result = roleLogic.unBindRolePermissionRelation(umsRolePermissionRelationDo);
        return R.result(result);
    }
}
